package com.shop.mapper;

import com.shop.entity.MerchantBasket;
import com.shop.entity.MerchantGoods;
import com.shop.entity.User;
import org.apache.ibatis.annotations.Param;

import java.util.List;

import com.shop.entity.Order;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * (Order)表数据库访问层
 *
 * @author makejava
 * @since 2020-11-21 12:10:56
 */
@Mapper
public interface OrderMapper extends BaseMapper<Order> {
    MerchantGoods getByGoodsId(Integer id);

    //查询id
    User getByUserId(Integer Id);

    int add(Order order);

    @Override
    int updateById(@Param("updated") Order updated);

    Order getByNo(@Param("no") String no);

    List<Order> selectByStatus(@Param("userId") Integer userId, @Param("status") String status);

    Order getOrderById(Integer orderId);

    @Select("select status from `order` where user_id=#{id}")
    List<Order> orderCount(Integer userId);

    List<MerchantBasket> selectBasket(@Param("merchantId") Integer merchantId
                                      ,@Param("userId") Integer userId);

    void deleteCartByUserAndMerchant(@Param("userId")Integer userId, @Param("merchantId")Integer merchantId);

    @Update("update `order` set status=1 where id=#{id}")
    void payOrder(Integer id);

    @Select("select inventory from merchant_goods where id=#{id}")
    Integer getNumByGoodsId(Integer id);
}
